package com.gjs.freechat.utils;

import info.debatty.java.stringsimilarity.MetricLCS;
import info.debatty.java.stringsimilarity.NormalizedLevenshtein;

import com.shamikm.similarity.JaccardIndexBasedSimilarity;

public class StringSimilartyUtils {
	public static double textSimilaryMeasure(String s1, String s2) {
		if (s1 == null || s2 == null || s1.length() == 0 || s2.length() == 0)
			return 0;
		NormalizedLevenshtein levenshtein = new NormalizedLevenshtein();
		//TextSimilarityMeasure longesCommonSubsequence = new LongestCommonSubsequenceNormComparator();
		MetricLCS longesCommonSubsequence = new MetricLCS();
		double score1 = levenshtein.similarity(s1, s2);
		double score2 = 0;
//		try {
//			score2 = longesCommonSubsequence.getSimilarity(s1, s2);
//		} catch (SimilarityException e) {
//			e.printStackTrace();
//		}
		score2 = 1 - longesCommonSubsequence.distance(s1, s2);
		return score1 >= score2 ? score1 : score2;
	}
	
	public static double wordsVectorSimilaryMeasure(String s1, String s2) {
		JaccardIndexBasedSimilarity jaccardIndexBasedSimilarity = new JaccardIndexBasedSimilarity();
		return jaccardIndexBasedSimilarity.calculateSimilarity(s1, s2);
	}
	
}
